package com.heima.wemedia.contyoller.v1;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dots.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {
        return wmMaterialService.uploadPicture(multipartFile);
    }

    @ApiOperation("查询素材")
    @PostMapping("/list")
    public ResponseResult findList(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.findList(dto);
    }

    @ApiOperation("删除素材")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPictureById(@PathVariable("id") Integer id) {
        return wmMaterialService.delPicture(id);
    }

    @GetMapping("collect/{id}")
    public ResponseResult coller(@PathVariable Integer id) {
        short type = 1;
        return wmMaterialService.updateStatus(id,type);
    }

    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable Integer id) {
        short type = 0;
        return wmMaterialService.updateStatus(id,type);
    }
}
